package com.xxgc.ssm.service.impl;

import com.xxgc.ssm.mapper.UsersMapper;
import com.xxgc.ssm.pojo.Users;
import com.xxgc.ssm.pojo.UsersExample;
import com.xxgc.ssm.pojo.info.Info;
import com.xxgc.ssm.service.IUserLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户登录业务逻辑
 * @Author tyl
 * @DATE 2021-12-7
 */
@Service
public class UserLoginServiceImpl implements IUserLoginService {
    @Autowired
    private UsersMapper usersMapper;
    public Info selectUserById(int uId) {
        Users users = usersMapper.selectByPrimaryKey(1l);
        if(users == null){
            return new Info(-1,"","没有该用户");
        }else{
            return new Info(1,"","查询成功");
        }

    }

    public Info userLogin(String uName, String uPass) {
        UsersExample example = new UsersExample();
        example.createCriteria().andUNameEqualTo(uName).andUPassEqualTo(uPass);
        List<Users> users = usersMapper.selectByExample(example);
        if(users!= null && users.size()>0){
            return new Info(1,users.get(0),"登录成功");
        }else{
            return new Info(-1,"","用户名或密码错误");

        }
    }
}
